#include "main/utils.h"
using namespace std;

void reverseString(string &str) {
  reverse(str.begin(), str.end());
  auto begin = str.begin();
  int pos = 0;
  size_t find_idx = 0;
  while (find_idx != string::npos) {
    find_idx = str.find(" ", pos);
    reverse(begin, str.begin() + find_idx);
    ++pos;
    begin = str.begin() + find_idx + 1;
  }
}

void rotateString(string &str, const int &num) {
  reverse(str.begin(), str.end());
  reverse(str.begin(), str.end() - num);
  reverse(str.end() - num, str.end());
}

int main() {
  string str = "I am a student.";
  reverseString(str);
  cout << "The reversed string is: " << str << endl;

  string str_rotate = "abcdefg";
  rotateString(str_rotate, 2);
  cout << "The rotated string is: " << str_rotate << endl;

  return 0;
}
